<template>
  <view>
    <button open-type="getRealtimePhoneNumber" @getrealtimephonenumber="getrealtimephonenumber">获取手机号</button>
  </view>
</template>

<script>
export default {
  data () {
    return {
    }
  },
  methods: {
    async getrealtimephonenumber(e) {
      console.log(e)
      if (e.detail.errMsg != 'getPhoneNumber:ok') {
        uni.$showMsg('获取手机号失败')
        return
      }
      const query = {
        code: e.detail.code
      }
      const {data: resp} = await uni.$http.post('/miniprogram/get_phone_number/', query)
      console.log(resp)
      uni.$showMsg('手机号:' + resp['wechatresp']['phone_info']['purePhoneNumber'])
    }
  }
}
</script>

<style scoped>

</style>